package org.bunny.vehicle.service;

import org.bunny.vehicle.entity.User;
import org.bunny.vehicle.util.JSON;
import org.bunny.vehicle.util.Utils;
import org.directwebremoting.annotations.RemoteProxy;
import org.directwebremoting.spring.SpringCreator;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;

@RemoteProxy(creator = SpringCreator.class)
@Service
public class UserService extends BaseService {

	/*
	 * （non-Javadoc）
	 * 
	 * @see org.bunny.vehicle.service.BaseService#getUser()
	 */
	@Override
	public User getUser() {
		return super.getUser();
	}

	public boolean save(String json) {
		JSONObject obj = JSON.parseObject(json);

		String phone = JSON.getString(obj, "phone");
		String password = JSON.getString(obj, "passwordNew");

		User user = getUser();
		if (null == user) {
			return false;
		}
		user.setPhone(phone);
		if (!Utils.isEmpty(password)) {
			user.setPassword(password);
		}
		return null != userRepository.save(user);
	}

}
